Test and restore behavior around to_json changing depth#906
Conversation
When serializing an Array, and one of the elements of the Array requires calling `to_json`, if the depth is changed, it will be used for the next entries, which wasn't the case before 5abd434, and is not the case with TruffleRuby and JRuby. Additionally, with TruffleRuby and JRuby the state's depth after the `to_json` call is used to close the Array, which isn't the case with CRuby.
Can't we fix that behavior rather than to encode it in test? |
|
Yeah I wasn't sure, I have other things I'd like to change about depth and I though maybe we could put them all together with a deprecation cycle. state = JSON::State.new
state.generate([].tap { _1 << _1 }) rescue nil
state.depth # => 100obj = Object.new
def obj.to_json(state)
state.depth += 1
"1"
end
state.generate(obj)
state.depth # => 1In both cases I think we should return 0. |
|
Generally speaking, I want to stop having a mutable Also generally speaking, I don't think anyone really use the dept argument, so if the behavior is currently wonky I'm fine changing it without deprecation. |
Reminds me, I should deprecate all the |
I think we'll need to keep depth mutable just for the old |
Truffle can use an undocumented method like |
Follow up to #903
When serializing an Array, and one of the elements of the Array requires calling
to_json, if the depth is changed, it will be used for the next entries, which wasn't the case before5abd434, and is not the case with TruffleRuby and JRuby.
Additionally, with TruffleRuby and JRuby the state's depth after the
to_jsoncall is used to close the Array, which isn't the case with CRuby.